package com.ggh.jinjilive.ui.mine.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemDiamondBinding;
import com.ggh.jinjilive.databinding.ItemMineDealDetailBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.mobile.mine.DiamondMobile;
import com.ggh.jinjilive.mobile.mine.TradingDetailMobile;

import java.util.List;

public class MineDealDetailAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<TradingDetailMobile> tradingDetailMobileList;

    public void setAdd(List<TradingDetailMobile> tradingDetailMobileList) {
        this.tradingDetailMobileList = tradingDetailMobileList;
        notifyDataSetChanged();
    }

    public void Add(List<TradingDetailMobile> tradingDetailMobileList) {
        this.tradingDetailMobileList.addAll(tradingDetailMobileList);
        notifyDataSetChanged();
    }



    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemMineDealDetailBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_mine_deal_detail, parent, false);
        return new ItemViewHolder(binding);
    }

    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder recyclerViewholder,final int position) {
        TradingDetailMobile tradingDetailMobile = tradingDetailMobileList.get(position);
        ItemViewHolder holder = (ItemViewHolder) recyclerViewholder;
        if(null != tradingDetailMobile){
            holder.binding.nameTransactionItem.setText(tradingDetailMobile.getTitle());
            holder.binding.dateTransactionItem.setText(tradingDetailMobile.getCreate_time());
            holder.binding.numTransactionItem.setText(tradingDetailMobile.getPrice() + tradingDetailMobile.getUnit());
        }
    }

    @Override
    public int getItemCount() {
        return null == tradingDetailMobileList ? 0 : tradingDetailMobileList.size();
    }


    class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemMineDealDetailBinding binding;
        public ItemViewHolder(@NonNull ItemMineDealDetailBinding binding) {
            super(binding.getRoot());
            this.binding = binding;

        }
    }

}